Use ggplot to create bar plots of year and program.
class=read.table("classInterests.txt",header = TRUE)
p1=ggplot(class, aes(x=Year))+
geom_bar(stat="Count", width=0.7, fill="steelblue")+
labs(title="Barplot of Year")
p2=ggplot(class, aes(x=Program))+
geom_bar(stat="Count", width=0.7, fill="steelblue")+
labs(title="Barplot of Program")
p3=ggplot(class, aes(x=Year,fill=Program))+
geom_bar()
ggplotly(p1)
ggplotly(p2)
ggplotly(p3)
Create plots of healthcare spending versus time color coded by states.
health_spending=read_csv("healthcare-spending.csv",skip=2)[1:52,]
## Parsed with column specification:
## cols(
## .default = col_double(),
## Location = col_character()
## )
## See spec(...) for full column specifications.
## Warning: 12 parsing failures.
## row col expected actual file
## 53 -- 25 columns 1 columns 'healthcare-spending.csv'
## 54 -- 25 columns 1 columns 'healthcare-spending.csv'
## 55 -- 25 columns 1 columns 'healthcare-spending.csv'
## 56 -- 25 columns 1 columns 'healthcare-spending.csv'
## 57 -- 25 columns 1 columns 'healthcare-spending.csv'
## ... ... .......... ......... .........................
## See problems(...) for more details.
health_spending=health_spending[!health_spending$Location=="United States",]
health=gather(health_spending,key="year",value="spending",2:25)
health$year=extract_numeric(health$year)
## extract_numeric() is deprecated: please use readr::parse_number() instead
p= ggplot(health, aes(year, spending)) +
geom_line(aes(group = Location), colour = "grey50") +
geom_point(aes(colour = Location))
ggplotly(p)
Create a barplot of average health care spending by state.
d=matrix(as.numeric(as.matrix(health_spending)[,-1]),ncol=24)
avespend=data.frame(spend=apply(d,1,mean),location=health_spending$Location)
p=ggplot(avespend, aes(location, spend)) +
geom_col(col="steelblue",fill="steelblue")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(p)